package com.zelin.sellergoods.service.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.zelin.dao.BrandDao;
import com.zelin.entity.BrandEntity;
import com.zelin.sellergoods.service.BrandService;
import com.zelin.utils.PageUtils;
import com.zelin.utils.Query;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


@Service
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        //1. 定义查询包装器对象
        QueryWrapper<BrandEntity> wrapper = new QueryWrapper<>();
        //2. 添加查询查询
        String key = (String) params.get("key");
        if(StringUtils.isNotBlank(key)){
            wrapper.like("name", key );
            wrapper.or().like("first_char",key );
            wrapper.or().like("id",key);
        }
        //3. 进行条件查询
        IPage<BrandEntity> page = this.page(
                new Query<BrandEntity>().getPage(params),
                wrapper
        );
        //4. 返回
        return new PageUtils(page);
    }

}